package com.simba.server.commands.impl.record;

import java.util.Map;
import com.simba.common.command.ICommand;
import org.apache.log4j.Logger;
import com.simba.common.database.DbOperator;
import com.simba.common.log.LogUtil;

public class RecordMachineStatusLocalCmd implements ICommand
{
	public static final String NAME = "RecordMachineStatusLocalCmd";
	private static final Logger logger = Logger.getLogger(RecordMachineStatusLocalCmd.class);
	private final Map<String, Object> paramMap;
	private final String sql = "insert into tt_machine_status_local(beginTime,endTime,status) values(?,?,?);";

	public RecordMachineStatusLocalCmd(Map<String, Object> paramMap)
	{
		this.paramMap = paramMap;
	}

	@Override
	public String getName()
	{
		return RecordMachineStatusLocalCmd.NAME;
	}

	@Override
	public Boolean run(Object params)
	{
		Boolean ret = false;

		if (!(params instanceof DbOperator))
		{
			return ret;
		}
		if (paramMap == null)
		{
			return ret;
		}
		try
		{
			DbOperator dbOperator = (DbOperator) params;

			dbOperator.prepareStatement(this.sql);

			Object beginTime = this.paramMap.get("beginTime");
			if ((beginTime == null) || beginTime.equals(""))
			{
				beginTime = "";
			}
			dbOperator.setString(1, beginTime.toString());

			Object endTime = this.paramMap.get("endTime");
			if ((endTime == null) || endTime.equals(""))
			{
				endTime = "";
			}
			dbOperator.setString(2, endTime.toString());

			Object status = this.paramMap.get("status");
			if ((status == null) || status.equals(""))
			{
				status = "";
			}
			dbOperator.setString(3, status.toString());
			int res = dbOperator.executeUpdate();
			if (res > 0)
			{
				ret = true;
			}
			else
			{
				ret = false;
			}

		}
		catch (Exception ex)
		{
			LogUtil.LogError(RecordMachineStatusLocalCmd.logger,
					"add machine status from tb_machine_status error: " + ex);
			ret = false;
		}
		return ret;
	}
}
